package pdfManager;

import java.io.File;
import java.io.IOException;

import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.util.PDFTextStripper;

public class PDFAdmin {
	private File f;
	private PDDocument pdDoc;
	private String ruta;
	private boolean valid = true;

	public PDFAdmin(String r) throws IOException {
		f = new File(r);
		ruta = r;
		try {
			pdDoc = PDDocument.load(f);
		} catch (Exception e) {
			valid = false;
			System.err.println("No existe archivo pdf");
		}
	}

	public String getRuta() {
		if (valid)
			return ruta;
		return "";
	}

	public int cantPages() {
		if (valid)
			return pdDoc.getNumberOfPages();
		return 0;
	}

	public String getPage(int n) {
		if (valid) {
			try {
				PDFTextStripper reader = new PDFTextStripper();
				reader.setStartPage(n);
				reader.setEndPage(n);
				String pageText = reader.getText(pdDoc);

				return pageText;

			} catch (Exception e) {
			}
		}
		return "";
	}

}
